﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace Wild2.Models.Aphorisms
{
    public class Aphorisms
    {
        public static string GetAphorism()
        {
            string aphorism = "";
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnect"].ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(@"SELECT TOP(1) [Text] FROM [Aphorisms] ORDER BY NEWID()", conn);
                cmd.Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    aphorism = reader["text"].ToString();
                }
                reader.Close();
                cmd.Connection.Close();
            }
            String nick = Wild2.Models.Auth.AuthOnSite.GetUserNick();
            return aphorism.Replace("{user}", nick ?? "");
        }
    }
}